import { apis } from '../../apis/apis'
import { requestPromise } from '../../utils/requestPromise';
import { isEmptyObject } from '../../utils/util'
Component({
  data: {
    detail: {},
    title:'',
  },
  methods:{
    adLoad() {
      console.log('Banner 广告加载成功')
    },
    adError(err:any) {
      console.error('Banner 广告加载失败', err)
    },
    adClose() {
      console.log('Banner 广告关闭')
    },
    async getDetail() {
      let _th = this;
      let app = getApp();
      if(isEmptyObject(app.globalData.detail)){
        console.log('没有global data')
        requestPromise({
          url: apis.getDetail,
          method: "GET",
          data: {},
        }).then((res:any)=>{
          wx.setStorageSync('detail', res.data.data.detail);
          _th.setData({
            detail: res.data.data.detail,
          });
        })
      }else{
        console.log('有global data')
        _th.setData({
          detail: app.globalData.detail,
        });
      }
    },
    backToHome() {
      wx.switchTab({
        url: '/pages/main/main',
      })
    },
    async onLoad(option:any) {
      let _th = this;
      _th.setData({
        title: option.title,
      });
      this.getDetail();
    },
  },
  lifetimes: {
    attached() {
    }
  },
})
